package com.dreamtour.controller;


import com.dreamtour.DTO.DailyTransactionDTO;
import com.dreamtour.entity.Transactions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.dreamtour.service.ITransactionsService;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xls
 * @since 2024-12-24
 */
@RestController
@RequestMapping("/transactions")
public class TransactionsController {
    @Autowired
    private ITransactionsService transactionsService;

    @RequestMapping("/getTransactionStats")
    public List<DailyTransactionDTO> getDailyTransactionStats() {
        return transactionsService.getDailyTransactionStats();
    }

    @GetMapping("/getTransactionRanges")
    public Map<String, Object> getTransactionRanges() {
        Map<String, Object> result = new HashMap<>();

        // 统计每个区间的交易总数
        result.put("0-200", transactionsService.getTransactionCountByRange(0, 200));
        result.put("200-500", transactionsService.getTransactionCountByRange(200, 500));
        result.put("500-1000", transactionsService.getTransactionCountByRange(500, 1000));
        result.put("1000-5000", transactionsService.getTransactionCountByRange(1000, 5000));
        result.put("5000+", transactionsService.getTransactionCountAbove(5000));

        return result;
    }

    @GetMapping("/getUserRatingStats")
    public Map<Integer, Integer> getUserRatingStats() {
        return transactionsService.getUserRatingStats();
    }
}
